home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 20 / jimutils / avail.a < prev    next >
Text File  |  1994-01-27  |  7KB  |  218 lines

  1. * Avail.a:    An assembler version of that 'popular' program.
  2. *
  3. * Author:
  4. *        James E. Cooper Jr.
  5. *        113-1B Collier Pl.
  6. *        Cary, NC  27513
  7. *
  8. * Notes:
  9. *        First working version. 10/87  jec
  10. *
  11. * Included equate files.
  12. * -----------------------------------------------------------------------
  13.     NOLIST
  14.     INCLUDE "exec/execbase.i"
  15.     INCLUDE "exec/memory.i"
  16.     INCLUDE "libraries/dos.i"
  17.     INCLUDE "offsets/exec.i"
  18.     INCLUDE "offsets/dos.i"
  19.     LIST
  20.  
  21.     ifd    CAPE
  22.     EXEOBJ
  23.     objfile 'ram:Avail'
  24.     optimon -1
  25.     endc
  26.  
  27. * Local Equates
  28. * ------------------------------------------------------------------------
  29. TRUE    EQU    -1
  30. FALSE    EQU    0
  31.  
  32. * A structure definition
  33. * -------------------------------------------------------------------------
  34.  
  35. v_CHIPSTR    EQU    -128    ; name
  36. v_CHIP        EQU    -124    ; storage for free chip parm
  37. v_ICHIP     EQU    -120    ;    "     "  chip in use
  38. v_MCHIP     EQU    -116    ;    "     "  max chip
  39. v_LCHIP     EQU    -112    ;    "     "  free chip largest hunk
  40. v_FASTSTR    EQU    -108
  41. v_FAST        EQU    -104    ;    "     "   "   fast parm
  42. v_IFAST     EQU    -100    ;    "     "  fast in use
  43. v_MFAST     EQU    -96    ;    "     "  max fast
  44. v_LFAST     EQU    -92    ;    "     "  free chip largest hunk
  45. v_TOTALSTR    EQU    -88
  46. v_TOTAL     EQU    -84    ;    "     "   "   total parm
  47. v_ITOTAL    EQU    -80    ;    "     "  total in use
  48. v_MTOTAL    EQU    -76    ;    "     "  Max total
  49. v_LTOTAL    EQU    -72    ;    "     "  free total largest hunk
  50. v_OUTPUT    EQU    -68    ; storage for output string
  51.  
  52. * The code segment
  53. * -------------------------------------------------------------------------
  54.  
  55.     link    a4,#-128        ; make space for variables
  56.  
  57.     moveq    #0,d0
  58.  
  59.     ;------ get Exec's library base pointer:
  60.     LEA.L    DOSName(PC),A1          ; name of dos library
  61.     moveq    #LIBRARY_VERSION,d0
  62.  
  63.     move.l    a0,a5            ; save A0 for later use
  64.     move.l    _AbsExecBase,a6
  65.     Call    OpenLibrary
  66.     MOVE.L    D0,a6            ; Save library pointer
  67.     BNE.S    gotdos
  68.  
  69.     moveq    #RETURN_FAIL,D0     ; give up
  70.     unlk    a4
  71.     rts                ; and get out of here!
  72.  
  73. gotdos:
  74. *
  75. *    ; REGISTER USAGE:
  76. *    ;    A0-2    = scratch
  77. *    ;    A3    = pointer to output string area, for store routine
  78. *    ;    A4    = pointer to variable storage
  79. *    ;    A5    = scratch
  80. *    ;    A6    = dos library base pointer
  81. *    ;    D0-3    = AmigaDOS scratch argument registers
  82. *    ;    D4    = scratch
  83. *    ;    D5    = output handle
  84. *    ;    D6    = DOSBase
  85. *
  86.     move.l    a4,d0            ; store away for later
  87.     moveq    #127,d4         ; initialize counter
  88. zero:
  89.     move.b    #0,-(a4)                ; zero the data space
  90.     dbra    d4,zero
  91.     move.l    d0,a4            ; and get the pointer again
  92. *    Obtain the output handle (needed for write)
  93.     Call    Output
  94.     move.l    a6,d6            ; save DOSBase for later calls
  95.     MOVE.L    D0,D5            ; Save for the write
  96.     move.l    _AbsExecBase,a6
  97.     Call    Forbid            ; don't let 'em change while we ask
  98.     move.l    MemList+LH_HEAD(a6),d0  ; first node in MemList
  99. checkchip:
  100.     move.l    d0,a5            ; move node address to address reg
  101.     move.w    MH_ATTRIBUTES(a5),d4    ; get node attributes
  102.     btst    #MEMB_CHIP,d4        ; is it chip?
  103.     beq.s    checkfast        ; no, go on
  104.     lea    v_CHIP(a4),a3           ; yes, add to chip totals
  105.     bsr    AddIt            ; call routine to add to totals
  106. checkfast:
  107.     btst    #MEMB_FAST,d4        ; is it fast?
  108.     beq.s    checkpublic        ; no, go on
  109.     lea    v_FAST(a4),a3           ; yes, add to fast totals
  110.     bsr.s    AddIt
  111. checkpublic:
  112.     btst    #MEMB_PUBLIC,d4     ; public?
  113.     beq.s    next            ; no
  114.     lea    v_TOTAL(a4),a3          ; yes, add it
  115.     bsr.s    AddIt
  116. next:
  117.     move.l    LN_SUCC(a5),d0          ; get address of next node
  118.     bne.s    checkchip        ; ...and loop back if valid
  119.     move.l    #MEMF_CHIP+MEMF_LARGEST,d1 ; to find largest hunk in chip ram
  120.     Call    AvailMem
  121.     move.l    d0,v_LCHIP(a4)          ; store
  122.     move.l    d0,d2            ; ...and save a copy
  123.     move.l    #MEMF_FAST+MEMF_LARGEST,d1 ; to find largest hunk in fast ram
  124.     Call    AvailMem
  125.     move.l    d0,v_LFAST(a4)          ; store
  126.     cmp.l    d0,d2            ; ...and find out which was larger
  127.     blt.s    ok            ; fast was larger
  128.     move.l    d2,d0            ; chip    "     "
  129. ok:
  130.     move.l    d0,v_LTOTAL(a4)         ; store largest of all
  131.     Call    Permit            ; done - they can load all they want
  132.     lea    CHIPNAME(PC),a1
  133.     move.l    a1,v_CHIPSTR(a4)        ; store string pointer for first line
  134.     addq.l    #CHIPLEN,a1
  135.     move.l    a1,v_FASTSTR(a4)        ;   "      "      "     "  second  "
  136.     addq.l    #FASTLEN,a1
  137.     move.l    a1,v_TOTALSTR(a4)       ; etc.
  138.     move.l    d5,d1            ; Output file handle
  139.     move.l    #TITLE,d2        ; pointer to buffer
  140.     moveq    #TITLEN,d3        ; number chars to write
  141.     bsr.s    printit         ; print the title
  142.     lea    v_CHIPSTR(a4),a1        ; CHIP first
  143.     bsr.s    printf
  144.     lea    v_FASTSTR(a4),a1        ; then FAST
  145.     bsr.s    printf
  146.     lea    v_TOTALSTR(a4),a1       ; and finally TOTAL
  147.     bsr.s    printf
  148.     moveq    #RETURN_OK,D0        ; give good return code
  149.     unlk    a4            ; clean up stack
  150.     rts                ; and get the ____ outa Dodge!
  151.  
  152. * Subroutines
  153. * ------------------------------------------------------------------------
  154. ******************************************************************************
  155. * AddIt:    routine to add memory parts to variables
  156. ******************************************************************************
  157.  
  158. AddIt:
  159.     move.l    MH_FREE(a5),d0
  160.     add.l    d0,(a3)                 ; add to available
  161.     move.l    MH_UPPER(a5),d0
  162.     sub.l    MH_LOWER(a5),d0
  163.     add.l    d0,8(a3)                ; add to Max section
  164.     move.l    8(a3),d0
  165.     sub.l    (a3),d0                 ; subtract available
  166.     move.l    d0,4(a3)                ; and we have in-use amount
  167.     rts
  168.  
  169. ******************************************************************************
  170. * printf:    print routine
  171. ******************************************************************************
  172.  
  173. printf:
  174.     lea    FMT(PC),a0              ; load format string
  175.     lea    store(PC),a2            ; routine that puts chars in output
  176.     lea    v_OUTPUT(a4),a3         ; where to put 'em
  177.     move.l    a3,a5            ; also, save it for PRINT
  178.     Call    RawDoFmt        ; have system 'make' output string
  179.     move.l    d5,d1            ; Output file handle
  180.     move.l    a5,d2            ; pointer to buffer
  181.     moveq    #127,d0         ; absurd number > max
  182.     moveq    #0,d3            ; init char count
  183. lenloop:
  184.     tst.b    (a5)+                   ; NULL yet?
  185.     beq.s    printit         ; yes, goforit!
  186.     addq.l    #1,d3            ; increment char count
  187.     dbra    d0,lenloop        ; and check again
  188. printit:
  189.     move.l    d6,a6            ; recover DOSBase
  190.     Call    Write            ; and print it all out!
  191.     move.l    _AbsExecBase,a6     ; and restore Exec Base for next call
  192.     rts
  193.  
  194. ******************************************************************************
  195. * STORE:    routine used by _LVORawDoFmt to store output string
  196. ******************************************************************************
  197.  
  198. store:
  199.     move.b    d0,(a3)+
  200.     rts
  201.  
  202. ******************************************************************************
  203. * Data declarations
  204. ******************************************************************************
  205.  
  206.     CNOP    0,4
  207. DOSName     DOSNAME
  208. CHIPNAME    DC.B    'chip',0
  209. CHIPLEN     EQU    *-CHIPNAME
  210. FASTNAME    DC.B    'fast',0
  211. FASTLEN     EQU    *-FASTNAME
  212. TOTALNAME    DC.B    'total',0
  213. TITLE        DC.B    'Type  Available    In-Use   Maximum   Largest',10
  214. TITLEN        EQU    *-TITLE
  215. FMT        DC.B    '%-5s  %8ld  %8ld  %8ld  %8ld',10,0
  216.     END
  217.  
  218.